package com.cloud.backend.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.*;

import com.cloud.backend.model.Menu;

@Mapper
public interface MenuDao {

	@Insert("insert into menu(parentId, name, url, css, sort, createTime, updateTime) "
			+ "values (#{parentId}, #{name}, #{url}, #{css}, #{sort}, #{createTime}, #{updateTime})")
	int save(Menu menu);

	int update(Menu menu);


//	private Long id;
//	private Long parentId;
//	private String name;
//	private String css;
//	private String url;
//	private Integer sort;
//	private Date createTime;
//	private Date updateTime;

//	@Select("select * from menu t where t.id = #{id}")
//	Menu findById(Long id);
	@Select("select * from menu t where t.id = #{id}")
	@Results( id = "menuMap", value = {
			@Result(property = "id",column = "id"),
			@Result(property = "parentId",column = "parentId"),
			@Result(property = "name",column = "name"),
			@Result(property = "css",column = "css"),
			@Result(property = "url",column = "url"),
			@Result(property = "sort",column = "sort"),
			@Result(property = "createTime",column = "createTime"),
			@Result(property = "updateTime",column = "updateTime"),

	})
	Menu findById(Long id);

	@Delete("delete from menu where id = #{id}")
	int delete(Long id);

	@Delete("delete from menu where parentId = #{id}")
	int deleteByParentId(Long id);

	@Select("select * from menu t order by t.sort")
	@ResultMap("menuMap")
	List<Menu> findAll();
}
